package com.pro.framework.api.model.dto;

import com.pro.framework.api.enums.EnumSortDirection;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class CursorQueryParam {
    private Long cursor;
    private Integer limit;
    private String orderBy = "id";
    private EnumSortDirection direction = EnumSortDirection.ASC;

    public CursorQueryParam(Long cursor, Integer limit) {
        this.cursor = cursor;
        this.limit = limit;
    }

    public boolean isValid() {
        return limit != null && limit > 0 && limit <= 5000;
    }

    public boolean hasCursor() {
        return cursor != null && cursor > 0;
    }

    // 静态构造方法
    public static CursorQueryParam of(Long cursor, Integer limit) {
        return new CursorQueryParam(cursor, limit);
    }

    public static CursorQueryParam of(Long cursor, Integer limit, String orderBy) {
        CursorQueryParam param = new CursorQueryParam(cursor, limit);
        param.setOrderBy(orderBy);
        return param;
    }
}